<%-- 
    Document   : loginbean
    Created on : 16-Jul-2013, 09:59:42
    Author     : MrMAD
--%>

<%@page import="sun.rmi.log.LogInputStream"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>

        <script src="../js/login.js"></script>
    </head>
    <body>
        <jsp:useBean id="customer" class="mybean.Customer"/>
        <jsp:setProperty name="customer" property="*"/>
        <%
            if (customer.getEmail() != null && customer.getEmail() != "" && customer.getPassword() != null && customer.getPassword() != "") {
                if (customer.authenticate()) {
                    customer.getInfoByEmail();
                    session.setAttribute("name", customer.getName());
                    session.setAttribute("email", customer.getEmail());
                    String referer = request.getHeader("Referer");
                    // handle empty referer.....
                    response.sendRedirect(referer);
                } else {

                    session.setAttribute("error", "Wrong email or password.");
                    String referer = request.getHeader("Referer");
                    // handle empty referer.....
                    response.sendRedirect(referer);
                }
            } else {
                session.setAttribute("error", "Please fill in email and password.");
                String referer = request.getHeader("Referer");
                // handle empty referer.....
                response.sendRedirect(referer);
            }
        %>
    </body>
</html>
